package com.sisyphus.mock.data;

import android.content.Context;

import com.sisyphus.mock.data.entities.PostEntity;
import com.sisyphus.mock.data.entities.UserEntity;
import com.sisyphus.mock.data.entities.UserPostFavoriteEntity;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

@Database(entities = {
        UserEntity.class,
        PostEntity.class,
        UserPostFavoriteEntity.class
}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {

    private static       AppDatabase INSTANCE;
    private static final Object      sLock         = new Object();
    private static final Migration   MIGRATION_1_2 = new Migration(1, 2) {

        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {

        }

    };

    public static void register(Context context) {
        synchronized (sLock) {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "sisyphus_mock.db")
//                        .addMigrations(MIGRATION_1_2)
                        .build();
            }
        }
    }

    public static AppDatabase get() {
        return INSTANCE;
    }


    public abstract UserMapper userMapper();

    public abstract PostMapper postMapper();

    public abstract UserPostFavoriteMapper userPostFavoriteMapper();

}
